{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# demo script for running CIDEr\n",
    "from __future__ import absolute_import\n",
    "from __future__ import division\n",
    "from __future__ import print_function\n",
    "\n",
    "from pydataformat.loadData import LoadData\n",
    "import pdb\n",
    "import json\n",
    "from pyciderevalcap.eval import CIDErEvalCap as ciderEval\n",
    "from collections import defaultdict\n",
    "\n",
    "pathToData = 'data/'\n",
    "\n",
    "refName = 'pascal50S.json'\n",
    "candName = 'pascal_candsB.json'\n",
    "\n",
    "result_file = 'results.json'\n",
    "df_mode = 'coco-val-df'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# load reference and candidate sentences\n",
    "loadDat = LoadData(pathToData)\n",
    "gts, res = loadDat.readJson(refName, candName)\n",
    "\n",
    "#res = res[:100]\n",
    "#gts = {img['image_id']: gts[img['image_id']] for img in res}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from pyciderevalcap.ciderD.ciderD import CiderD\n",
    "from pyciderevalcap.cider.cider import Cider\n",
    "from pyciderevalcap.tokenizer.ptbtokenizer import PTBTokenizer\n",
    "tokenizer = PTBTokenizer('gts')\n",
    "_gts = tokenizer.tokenize(gts)\n",
    "tokenizer = PTBTokenizer('res')\n",
    "_res = tokenizer.tokenize(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "scorer = Cider(df='coco-val')\n",
    "scorerD = CiderD(df='coco-val')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5580180601041953\n",
      "0.4594128636973375\n"
     ]
    }
   ],
   "source": [
    "score, scores = scorer.compute_score(_gts, _res)\n",
    "scoreD, scoresD = scorerD.compute_score(_gts, _res)\n",
    "print(score)\n",
    "print(scoreD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
